
package example.ilm.utils;

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Robot;
import java.awt.Toolkit;
import java.io.File;


public class Screenshot {
    public static void takeScreenShot(String savePath, String fileName){
        Robot robot = null;
                try {
                    Toolkit toolkit = Toolkit.getDefaultToolkit();
                    Dimension dimension = toolkit.getScreenSize();
                    
                    int x =0,y = 0;
                    int w = dimension.width;
                    int h = dimension.height;
                    boolean fullscreen = true;
                    if(!fullscreen){
                     /*   x = IlmDomainGUI.this.getX();
                        y = IlmDomainGUI.this.getY();
                        w = IlmDomainGUI.this.getWidth();
                        h = IlmDomainGUI.this.getHeight();*/
                    }
                    
                    robot = new Robot(GraphicsEnvironment.getLocalGraphicsEnvironment()
                            .getDefaultScreenDevice());
                    java.awt.image.BufferedImage bf = robot.createScreenCapture(new java.awt.Rectangle(x, y,
                            w, h));
                    if(fileName==null){
                        fileName = "screenshot_"+System.currentTimeMillis()+".png";
                    }
                    javax.imageio.ImageIO.write(bf, "PNG", new File(savePath+fileName));
                } catch (Exception e) {
                    System.out.println("Erro ao criar o Robô");
                }
    }
}
